package cn.charmaine.basic.base.service.impl;

import cn.charmaine.basic.base.mapper.IBaseMapper;
import cn.charmaine.basic.base.query.BaseQuery;
import cn.charmaine.basic.base.service.IBaseService;
import cn.charmaine.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private IBaseMapper<T> mapper;

    @Override
    public void add(T t) {
        mapper.insert(t);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteById(id);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public T queryById(Long id) {
        return mapper.selectById(id);
    }

    @Override
    public List<T> queryAll() {
        return mapper.selectAll();
    }

    @Override
    public PageList<T> queryData(BaseQuery query) {
        Long count = mapper.count(query);
        List<T> rows = mapper.rows(query);
        return new PageList<T>(count,rows);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        mapper.batchDelete(ids);
    }
}
